package com.hex.ds.hdrs.center.service;

import com.hex.ds.hdrs.center.dao.MasterCenterInfoDao;
import com.hex.ds.hdrs.center.po.MasterCenterInfo;
import com.hex.ds.hdrs.common.utils.BaseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
@Slf4j
public class MasterCenterInfoService {

    @Autowired
    private MasterCenterInfoDao masterCenterInfoDao;

    /**
     * 抢占DB
     *
     * @param map
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public boolean grabDb(Map map) {
        log.debug("抢占DB【MasterCenterInfoService.grabDb】========");
        return this.masterCenterInfoDao.grabDb(map);
    }

    /**
     * 查询
     * @return
     */
    public MasterCenterInfo qry(){
        log.info("查询【MasterCenterInfoService.qry】========");
        return this.masterCenterInfoDao.qry();
    }

    /**
     * @Method: add
     * @Param: [map]
     * @Return: void
     * @Description: 新增master节点
     * @Author: ji.tang
     * @Date: 2022/11/22 15:30
     * @Version: V1.0
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void add(Map map){
        log.info("新增【MasterCenterInfoService.add】========");
        map.put("pkId", BaseUtil.getPkId());
        this.masterCenterInfoDao.add(map);
    }

    /**
     * @Method: update
     * @Param: [map]
     * @Return: void
     * @Description: 更新master节点
     * @Author: ji.tang
     * @Date: 2022/11/22 15:30
     * @Version: V1.0
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void update(Map map){
        log.info("更新【MasterCenterInfoService.update】========");
        this.masterCenterInfoDao.update(map);
    }
}
